import * as actionTypes from './constants';
import axios from 'axios';
import { fromJS } from 'immutable';

const setList = (list, totalPage) => ({
  type: actionTypes.SET_LIST,
  list: fromJS(list),
  totalPage,
});

export const searchFocus = () => ({
  type: actionTypes.SERACH_FOCUSE,
});
export const searchBlur = () => ({
  type: actionTypes.SERACH_BLUR,
});
export const getList = () => {
  return (dispatch) => {
    axios
      .get('/api/headerList.json')
      .then((res) => {
        const totalPage = Math.ceil(res.data.data.length / 10);
        dispatch(setList(res.data.data, totalPage));
      })
      .catch((e) => {
        console.log(e);
      });
  };
};
export const handleChange = (page) => ({
  type: actionTypes.HANDLE_CHANGE,
  page,
});
export const handleMouseLeave = () => ({
  type: actionTypes.MOUSE_LEAVE,
});
export const handleMouseEnter = () => ({
  type: actionTypes.MOUSE_ENTER,
});
